package com.yanq.liancar.adapter;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.yanq.liancar.R;
import com.yanq.liancar.bean.ServiceTypeBean;
import com.yanq.liancar.bean.SmallCFuelFillBean;
import com.yanq.liancar.util.LogUtils;

import java.util.List;

public class GvServiceAdapter extends BaseAdapter {
    private Context context;
    public List<ServiceTypeBean> datas;
    private LayoutInflater layoutInflater;

    public GvServiceAdapter(Context context, List<ServiceTypeBean> list) {
        LogUtils.e("22222", list.size() + "");
        this.context = context;

        this.datas = list;

        layoutInflater = LayoutInflater.from(context);

    }

    //    @Override
//    public int getCount() {
//        return datas.size() + 1;
//    }
    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    //    @Override
//    public View getView(int position, View convertView, ViewGroup parent) {
//
//        LogUtils.e("dasdadasda", "asdadada" + "++++++++" + datas.size());
//        ViewHolder holder = null;
//        if (convertView == null) {
//            holder = new ViewHolder();
//            convertView = layoutInflater.inflate(R.layout.item_service, parent, false);
//            holder.textView = convertView.findViewById(R.id.service_textviewaA);
//            holder.imageView = convertView.findViewById(R.id.service_img);
//            convertView.setTag(holder);
//        } else {
//            holder = (ViewHolder) convertView.getTag();
//        }
//        if (position < datas.size()) {
//            holder.textView.setText(datas.get(position).getName());
//            holder.imageView.setVisibility(View.GONE);
//
//            if (datas.get(position).isChecked()) {
//                holder.textView.setBackground(context.getResources().getDrawable(R.drawable.selector_tv_bg_d));
//                holder.textView.setTextColor(Color.WHITE);
//            } else {
//                holder.textView.setBackground(context.getResources().getDrawable(R.drawable.selector_tv_bg_c));
//                holder.textView.setTextColor(context.getResources().getColor(R.color.background_content));
//            }
//        } else {
//            holder.imageView.setVisibility(View.VISIBLE);
//            holder.textView.setVisibility(View.GONE);
//        }
//
//        return convertView;
//    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        Log.e("dasdadasda", "asdadada" + "++++++++" + datas.size());
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = layoutInflater.inflate(R.layout.item_service, parent, false);
            holder.textView = convertView.findViewById(R.id.service_textviewaA);
            holder.imageView = convertView.findViewById(R.id.service_img);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.textView.setText(datas.get(position).getName());
        if (datas.get(position).isChecked()) {
            holder.textView.setBackground(context.getResources().getDrawable(R.drawable.selector_tv_bg_d));
            holder.textView.setTextColor(Color.WHITE);
        } else {
            holder.textView.setBackground(context.getResources().getDrawable(R.drawable.selector_tv_bg_c));
            holder.textView.setTextColor(context.getResources().getColor(R.color.background_content));
        }


        return convertView;
    }

    static class ViewHolder {
        TextView textView;
        ImageView imageView;
    }

    public void setData(List<ServiceTypeBean> list) {
        this.datas = list;
        notifyDataSetChanged();
        Log.e("dasdadasda", "asdadada" + "=========" + list.size());

    }
}
